package cn.itsource.controller.app;


import cn.itsource.pojo.bo.OrderToDriver;
import cn.itsource.pojo.dto.OrderCreateDto;
import cn.itsource.pojo.vo.ExecuteOrderInfoForCustomerVO;
import cn.itsource.pojo.vo.ExecuteOrderInfoForDriverVO;
import cn.itsource.result.JSONResult;
import cn.itsource.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Tag(name = "订单表",description = "订单表")
@RestController
@RequestMapping("/app/order")
public class AppOrderController {

    @Autowired
    public IOrderService orderService;

    @Operation( summary= "结束代驾",description = "结束代驾")
    @PostMapping("/endDriving/{orderNo}")
    public JSONResult endDriving(@PathVariable String orderNo){
        orderService.endDriving(orderNo);
        return JSONResult.success();
    }

    @Operation( summary= "开始代驾",description = "开始代驾")
    @PostMapping("/start/{orderNo}")
    public JSONResult start(@PathVariable String orderNo){
        orderService.start(orderNo);
        return JSONResult.success();
    }

    @Operation( summary= "到达代驾点",description = "到达代驾点")
    @PostMapping ("/arrive/{orderNo}")
    public JSONResult arrive(@PathVariable String orderNo){
         orderService.arrive(orderNo);
        return JSONResult.success();
    }

    @Operation( summary= "查询订单是否被接单",description = "查询订单是否被接单")
    @GetMapping("/isaccpet/{orderNo}")
    public JSONResult isAccpet(@PathVariable String orderNo){
        Boolean isAccpet = orderService.isAccpet(orderNo);
        return JSONResult.success(isAccpet);
    }

    @Operation( summary= "加载乘客进行中的订单",description = "加载乘客进行中的订单")
    @GetMapping("/inprocess/forcustomer")
    public JSONResult pullInprocessForCurrentCustomer(){
         ExecuteOrderInfoForCustomerVO vo = orderService.pullInprocessForCurrentCustomer();
        return JSONResult.success(vo);
    }

    @Operation( summary= "加载司机进行中的订单",description = "加载司机进行中的订单")
    @GetMapping("/inprocess/fordriver")
    public JSONResult pullInprocessForCurrentDriver(){
        ExecuteOrderInfoForDriverVO driverVO = orderService.pullInprocessForCurrentDriver();
        return JSONResult.success(driverVO);
    }

    @Operation( summary= "保存Order",description = "基础对象保存接口")
    @Parameter(name = "order",description = "保存的对象",required = true)
    @PostMapping("/create")
    public JSONResult save(@RequestBody @Valid OrderCreateDto dto){
    String order = orderService.create(dto);
        return JSONResult.success(order);
    }

    @Operation( summary= "司机拉取订单",description = "司机拉取订单")
    @GetMapping("/pull")
    public JSONResult pullForCurrentDriver(){
        List<OrderToDriver> result =  orderService.pullForCurrentDriver();
        return JSONResult.success(result);
    }

    @Operation( summary= "自动取消订单",description = "自动取消订单")
    @PostMapping("/auto/cancel/{orderNo}")
    public JSONResult autoCancel(@PathVariable String orderNo){
        orderService.autoCancel(orderNo);
        return JSONResult.success();
    }

    @Operation( summary= "司机执行抢单",description = "司机执行抢单")
    @PostMapping("/kill/{orderNo}")
    public JSONResult kill(@PathVariable String orderNo){
        orderService.kill(orderNo);
        return JSONResult.success();
    }


}
